package com.hkbigdata.sybx.mapper;


/**
 * @author yangjing
 * @creat 2025-05-06-15:05
 * @email 3010335359@qq.com
 */

import com.hkbigdata.sybx.bean.ElderRegedit;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ElderRegeditMapper {
    // 根据用户ID查询老人记录
    @Select("SELECT * FROM elder_regedit WHERE user_id = #{user_id}")
    ElderRegedit getUserBeanByUserId(String user_id);

    // 插入记录
    @Options(useGeneratedKeys = false)
    @Insert("INSERT INTO elder_regedit (name, gender, age, height, weight, birth_date, id_number, address, emergency_phone, medical_history, allergy, user_id) " +
            "VALUES (#{name}, #{gender}, #{age}, #{height}, #{weight}, #{birth_date}, #{id_number}, #{address}, #{emergency_phone}, #{medical_history}, #{allergy}, #{user_id})")
    int addUser(ElderRegedit elderRegedit);

    // 删除记录
    @Delete("DELETE FROM elder_regedit WHERE user_id = #{user_id}")
    int deleteUserByUserId(String user_id);

    // 修改记录
    @Update("UPDATE elder_regedit SET name = #{name}, gender = #{gender}, age = #{age}, " +
            "height = #{height}, weight = #{weight}, birth_date = #{birth_date}, id_number = #{id_number}, address = #{address}, " +
            "emergency_phone = #{emergency_phone}, medical_history = #{medical_history}, allergy = #{allergy} " +
            "WHERE user_id = #{user_id}")
    int updateUser(ElderRegedit elderRegedit);

//    查看全部老人信息
    @Select("SELECT * FROM elder_regedit")
    List<ElderRegedit> getAllUsers();

}